<?php

namespace app\admin\behavior;

use think\Cache;
use think\Request;
use think\Session;
use think\Config;

/**
 * Class FilterAuth
 * @package app\admin\behavior 权限过滤
 */
class FilterAuth
{

    public function run(&$params)
    {

        $AuthRoler = [
            "admin/agent/save",
            "admin/staff/save",
            "admin/agent/editdaili",
            "admin/staff/editdaili",
        ];

        $modeule = strtolower($params->module());
        //当前控制器名称
        $controller = strtolower($params->controller());
        //当前操作名称
        $action = strtolower($params->action());
        $actions = $modeule."/".$controller."/".$action;
        $sid = w_g("sid");
        if($sidRow =  Cache::get($sid)){
            //privilege
            $admin_group_id = $sidRow['admin_group_id'];
            $roleModel = new \app\admin\model\Role();
            $roleModelReult =  $roleModel->where("id",$admin_group_id)->find();
            if($roleModelReult['privilege']!="all"){
                if(in_array($actions,$AuthRoler)){
                    if(!$sidRow['is_manger']){
                        exit(json_encode(resJson(0,"你不是代理商管理者,暂时不能操作")->getData()));
                    }
                }
            }


        }



    }

}
